#!/bin/bash
dir1=$1
dir2=$2
record="record.txt"
if [ ! -d $dir1 ]; then
    echo "dir1 does not exist"
    exit 1
fi
if [ ! -d $dir2 ]; then
    echo "dir2 does not exist"
    exit 1
fi
if [ ! -f $record ]; then
    touch $record
fi
for file in $(ls $dir2)
do
    if [ ! -f "$dir1/$file" ] || [ "$dir2/$file" -nt "$dir1/$file" ]; then
        cp "$dir2/$file" "$dir1"
        echo "Copied $file from $dir2 to $dir1" >> $record
    fi
done